//
//  ServiceViewController.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/19.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class ServiceViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        configUI()
        initBaseLayout()
        layoutPageSubviews()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    // MARK: - private method
    func configUI() {
        self.view.backgroundColor = UIColor.white
        initNavItem(controller: self, imageName: "nav_back_n", highlitedImageName: "nav_back_h", selectedImageName: "", isLeft: true)
        self.title = "服务与反馈"
    }
    
    func initBaseLayout() {
        self.view.addSubview(tableView)
    }
    
    func layoutPageSubviews() {
        tableView.snp.makeConstraints { (make) in
            make.edges.equalTo(self.view).inset(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
        }
    }
    
    // MARK: - setters and getters
    var _tableView: UITableView!
    var tableView: UITableView {
        if _tableView == nil {
            _tableView = UITableView()
            _tableView.backgroundColor = UIColor(hexString: "#EEEEEE")
            _tableView.delegate = self
            _tableView.dataSource = self
            _tableView.register(SettingCell.self, forCellReuseIdentifier: "SettingCell")
        }
        return _tableView
    }
}

extension ServiceViewController: UITableViewDelegate, UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 2
        } else if section == 1 {
            return 1
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let string = "SettingCell"
        let cell = tableView.dequeueReusableCell(withIdentifier: string, for:
            indexPath) as! SettingCell

        let dataSource = [["联系我们", "意见反馈"], ["电话客服"]]
        cell.configUI(content: dataSource[indexPath.section][indexPath.row])
        if indexPath.section == 1 && indexPath.row == 0 {
            cell.isPhone = true
        } else {
            cell.isPhone = false
        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 16
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
}
